package com.hzy.servlet;

import com.hzy.service.RentService;
import com.hzy.utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Package: com.hzy.servlet
 * @ClassName: ListServlet
 * @Author: 862982795
 * @CreateTime: 2021/06/22 19:19
 * @Description:
 */
@WebServlet("/ListServlet")
public class ListServlet extends HttpServlet {
    static Integer count = 0;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        count++;
        System.out.println("count=" + count + "次");
        RentService service = new RentService();

        Page page = new Page();

        //查询的条件
        String currPageNoStr = req.getParameter("currPageNo");//查询的页面

        String pageSizeStr = req.getParameter("pageSize");//单页显示的记录数
        String userName = req.getParameter("userName");//用户名
        String carNum = req.getParameter("carNum");//车牌号

        page.setUserName(userName);
        page.setCarNum(carNum);
        page.setCurrPageNo(currPageNoStr);
        page.setPageSize(pageSizeStr);
        page.setTotalCount(service.getCount(page));
        page.setRentList(service.getRentListByUserNameAndCarNumAndLimit(page));

        req.setAttribute("page", page);
        req.getRequestDispatcher("list.jsp").forward(req, resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
